﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GomeeSoft.src.control
{
    public partial class UCListboxCombo : UCCombo
    {
        public UCListboxCombo()
        {
            InitializeComponent();
            InitializeCombo(listBox1);
        }

        public event EventHandler SelectedChanged;

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownState == DropDownStateEnum.Opening || DropDownState == DropDownStateEnum.Closing)
                return;

            if (listBox1.SelectedItems.Count == 0)
                return;

            Text = listBox1.SelectedItems[0].ToString();
            CloseDropDown();
            if (SelectedChanged != null)
                SelectedChanged(null, null);
        }

        public void AddItem(string item)
        {
            listBox1.Items.Add(item);
            if (listBox1.Items.Count == 1)
                Text = item;
        }
    }
}
